// 公共方法封装
import store from '@/store/index'

async function getUserInfo() {
	if (!uni.getStorageSync('userInfo')) {
		uni.reLaunch({
			url: '/pages/login/login'
		})
		return;
	}
	if (uni.getStorageSync('userInfo')) {
		let user = await uni.$u.api.getUserInfo({
			phone: uni.getStorageSync('phone'),
		})
		uni.setStorageSync('userInfo', JSON.stringify(user.data))
		return userInfo;
	}
	return;
}

function showModal(option) {
	if (option.constructor === Object) {
		store.commit('modal/showModal', option)
	}
}

function changeState(option) {
	if (option.constructor === Object) {
		store.commit('transfer/changeState', option)
	}
}

export const api = {
	showModal,
	changeState,
	getUserInfo
}
